package org.aeon.gamechatnest.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.aeon.gamechatnest.common.response.ResultBuild;
import org.aeon.gamechatnest.dto.ChatMessageMatchDto;
import org.aeon.gamechatnest.pojo.ChatMessage;
import org.aeon.gamechatnest.service.PrivateChatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author MissingAeon
 * @date 2024/5/20 17:27
 * @description
 */

@Validated
@RestController
@RequestMapping("/private/message")
@Tag(name = "PrivateChatMessageControllerApi", description = "私人聊天消息控制器类API")
public class PrivateChatMessageController {

    @Autowired
    private PrivateChatMessageService privateChatMessageService;


    // TODO @PreAuthorize("")
    @Operation(summary = "获取一个私信的历史消息", description = "获取一个私信的历史消息", parameters = {
            @Parameter(name = "targetId", description = "目标私信id")
    })
    @GetMapping
    public Object getHistoricalMessages(@Validated ChatMessageMatchDto chatMessageOperation) {
        List<ChatMessage> chatMessages = privateChatMessageService.historyMessage(chatMessageOperation);
        return ResultBuild.result().successful().data(chatMessages).build();
    }

    // TODO @PreAuthorize("")
    @Operation(summary = "删除一条消息", description = "删除一条消息", parameters = {
            @Parameter(name = "targetId", description = "目标私信id")
    })
    @DeleteMapping("{messageId}")
    public Object deleteHistoricalMessages(@PathVariable("messageId") String messageId) {
        List<ChatMessage> chatMessages = privateChatMessageService.removeById(messageId);
        return ResultBuild.result().successful().data(chatMessages).build();
    }

}
